import java.util.Stack;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Ding
 * @create 2022/9/14 15:34
 */
public class Main7 {
    public static void main(String[] args) {
        String str = "abcbabcba";
        char delChar = 'a';

        int l = 0;
        while (true){
            if (str.charAt(l) == delChar){
                l++;
            }else{
                break;
            }
        }

        str = str.substring(l);

        Stack<Character> stack = new Stack<>();
        for (char c : str.toCharArray()) {
            stack.push(c);
        }

        while (!stack.isEmpty()){
            if (stack.peek() == delChar){
                stack.pop();
            }else{
                break;
            }
        }

        StringBuilder sb = new StringBuilder();
        while (!stack.isEmpty()){
            sb.append(stack.pop());
        }

        System.err.println(sb.reverse().toString());
    }
}
